package com.cskaoyan.day16;

import java.util.Random;


public class CountArray {
    public static void main(String[] args) {
        String[] str = getArras();
        for (int i = 0; i < str.length; i++) {
            if (i % 20 == 0 && i != 0) {
                System.out.println();
            }
            System.out.printf(str[i] + "\t");
        }
        System.out.println();
        for (int i = 0; i < str.length - 2; i++) {
            int count = 1;
            if (str[i] == null) {
                continue;
            }
            for (int j = i + 1; j < str.length - 1; j++) {
                if (str[j] == null) {
                    continue;
                }
                if (str[i].equals(str[j])) {
                    count++;
                    str[j] = null;
                }
            }
            if (count >= 2) {
                System.out.println(str[i] + "发生了重复 重复了" + count + "次");
            }

        }
    }


    public static String[] getArras() {
        int numStrings = 100;
        int stringLength = 2;
        String[] str = new String[numStrings];
        String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();

        for (int i = 0; i < numStrings; i++) {
            StringBuilder sb = new StringBuilder(stringLength);
            for (int j = 0; j < stringLength; j++) {
                int index = random.nextInt(alphabet.length());
                char randomChar = alphabet.charAt(index);
                sb.append(randomChar);
            }
            str[i] = sb.toString();
        }
        return str;
    }
}



